package com.angel.bo.admin.service.impl;

import com.angel.bo.admin.mapper.DictInfoMapper;
import com.angel.bo.admin.service.DictInfoService;
import com.angel.bo.admin.service.DictService;
import com.angel.bo.auth.client.jwt.AuthUtil;
import com.angel.bo.beans.admin.entity.Dict;
import com.angel.bo.beans.admin.entity.DictInfo;
import com.angel.bo.cache.annotation.ServiceCache;
import com.angel.bo.cache.constant.ServiceCacheActionEnum;
import com.angel.bo.cache.model.CacheType;
import com.angel.bo.common.msg.WebReturn;
import com.angel.bo.common.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


/**
 * @author ${author}
 * @email haibo.mei@ge.com
 * @date 2018-02-02 15:03:26
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DictInfoServiceImpl extends BaseServiceImpl<DictInfoMapper, DictInfo> implements DictInfoService {


    @Autowired
    private DictInfoMapper dictInfoMapper;

    @Autowired
    private DictService dictService;

    @Autowired
    private AuthUtil authUtil;

    /**
     * @param dictInfo
     * @Author: Haibo.Mei [Haibo.Mei@ge.com]
     * @Description:
     * @Date: 16:04 2018/2/2
     */
    @Override
    public WebReturn<DictInfo> saveDictInfo(DictInfo dictInfo) {
        dictInfo.setCreateDate(new Date());
        dictInfo.setCreateUserId(authUtil.getUserIdFromToken());
        this.insert(dictInfo);
        return new WebReturn<>(dictInfo);
    }

    /**
     * 获取字典详情
     *
     * @param dictInfo
     * @return
     */
    @Override
    @ServiceCache(action = ServiceCacheActionEnum.ADD,scope = CacheType.DICT_INFO_TRANSLATION,keyExpression="#dictInfo.dictCode")
    public WebReturn getDictInfo(DictInfo dictInfo) {
        List<DictInfo> dictInfoList = dictInfoMapper.queryDictInfoList(dictInfo);
        WebReturn webReturn = new WebReturn();
        webReturn.setData(dictInfoList);
        return webReturn;
    }


}



